﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Text;
using System.Windows.Forms;
using TripLOAMobile.GPS;
using TripLOAMobile.InternalEntities;
using CompactFramework.Utilities.Localization;

namespace TripLOAMobile
{
    public delegate void Activate();
    /// <summary>
    /// The root form of the application
    /// </summary>
    public partial class Welcome : LocalizedForm
    {
        //private /*const*/ int maxNumberOfResult=4;/*=3*/
        /// <summary>
        /// The singleton that will be used by all the forms to access to the data (cached o from a web service)
        /// </summary>
        internal static RemoteResourceProvider rrp;
        internal const int MaxnumberOfResult = 5;//ListViewTravelControl.MAXTRAVELSFORPAGE;
        #region GPS declarations
        internal static Gps gps = new Gps();
        #endregion
        public Activate DelegateActivate;
        private AnimationControl animation;

        private Image standardAvatar;
        internal static FormBuffer formBuffer;

        //may be sostituited by m_ActualForm...
        private Login m_LoginForm;

        private Bitmap m_DoubleBuffer; //Used to avoid flickering effects on paint procedure

        /// <summary>
        /// Initializes the <see cref="Welcome"/> class.
        /// </summary>
        static Welcome()
        {
            rrp = new RemoteResourceProvider();
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="Welcome"/> class.
        /// </summary>
        public Welcome()
        {
            ResourceManager.Instance.Culture = new System.Globalization.CultureInfo("en-US");
            InitializeComponent();
            InternalEventManaging();
            DelegateActivate = new Activate(this.Activate);
            #region DoubleBufferInitialization
            Size cSz = ClientSize;
            m_DoubleBuffer = new Bitmap(cSz.Width, cSz.Height);
            FillDoubleBuffer();
            #endregion

            #region creation of the control for the animation
            animation = new AnimationControl();
            int x = this.Width / 2 - animation.Width / 2;
            int y = this.Height / 2 - animation.Height / 2;
            animation.Location = new Point(x, y);
            this.Controls.Add(animation);
            animation.BringToFront();
            #endregion
            formBuffer = new FormBuffer(this);
            m_LoginForm = new Login();
            standardAvatar = this.btn_avatar.Image;
            this.menuItem2.Enabled = false;
            UpdateResources();
        }

        #region start/stop animation
        delegate void animationDel();
        private void stopAnimation()
        {
            this.animation.StopAnimation();
            foreach (Control c in this.Controls)
            {
                c.Enabled = true;
            }
        }
        private void startAnimation()
        {
            foreach (Control c in this.Controls)
            {
                c.Enabled = false;
            }
            this.animation.StartAnimation();
        }
        #endregion

        #region ButtonVisualizationHandling
        /// <summary>
        /// Provides the registration, for each button, to the events that control their visualization state.
        /// </summary>
        private void InternalEventManaging()
        {
            //btn_search
            this.btn_search.MouseMove += new MouseEventHandler(btn_search_MouseMove);
            this.btn_search.MouseDown += new MouseEventHandler(btn_search_MouseDown);

            //btn_insert
            this.btn_insert.MouseMove += new MouseEventHandler(btn_insert_MouseMove);
            this.btn_insert.MouseDown += new MouseEventHandler(btn_insert_MouseDown);

            //btn_favs
            this.btn_favs.MouseMove += new MouseEventHandler(btn_favs_MouseMove);
            this.btn_favs.MouseDown += new MouseEventHandler(btn_favs_MouseDown);

            //btn_offered
            this.btn_offered.MouseMove += new MouseEventHandler(btn_offered_MouseMove);
            this.btn_offered.MouseDown += new MouseEventHandler(btn_offered_MouseDown);

            //btn_booked
            this.btn_booked.MouseMove += new MouseEventHandler(btn_booked_MouseMove);
            this.btn_booked.MouseDown += new MouseEventHandler(btn_booked_MouseDown);

            //btn_config
            this.btn_config.MouseMove += new MouseEventHandler(btn_config_MouseMove);
            this.btn_config.MouseDown += new MouseEventHandler(btn_config_MouseDown);
        }

        //The following methods change the state of the buttons, when theese are pressed
        void btn_search_MouseDown(object sender, EventArgs e)
        {
            this.btn_search.Image = Properties.Resources.searchdown;
            Invalidate();
            Update();
        }

        void btn_insert_MouseDown(object sender, EventArgs e)
        {
            this.btn_insert.Image = Properties.Resources.insertdown;
            Invalidate();
            Update();
        }

        void btn_booked_MouseDown(object sender, EventArgs e)
        {
            this.btn_booked.Image = Properties.Resources.bookeddown;
            Invalidate();
            Update();
        }

        void btn_offered_MouseDown(object sender, EventArgs e)
        {
            this.btn_offered.Image = Properties.Resources.offereddown;
            Invalidate();
            Update();
        }

        void btn_config_MouseDown(object sender, EventArgs e)
        {
            this.btn_config.Image = Properties.Resources.configdown;
            Invalidate();
            Update();
        }

        void btn_favs_MouseDown(object sender, EventArgs e)
        {
            this.btn_favs.Image = Properties.Resources.favsdown;
            Invalidate();
            Update();
        }
        
        //The following methods resolve freezing of a button in the case that it is left after a mousedown
        private void btn_search_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            if (!btn_search.Bounds.Contains(e.X, e.Y))
                this.btn_search.Image = Properties.Resources.searchup;
        }

        private void btn_booked_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            if (!btn_booked.Bounds.Contains(e.X, e.Y))
                this.btn_booked.Image = Properties.Resources.bookedup;
        }

        private void btn_insert_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            if (!btn_insert.Bounds.Contains(e.X, e.Y))
                this.btn_insert.Image = Properties.Resources.insertup;
        }

        private void btn_offered_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            if (!btn_offered.Bounds.Contains(e.X, e.Y))
                this.btn_offered.Image = Properties.Resources.offeredup;
        }

        private void btn_config_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            if (!btn_config.Bounds.Contains(e.X, e.Y))
                this.btn_config.Image = Properties.Resources.configup;
        }

        void btn_favs_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            if (!btn_favs.Bounds.Contains(e.X, e.Y))
                btn_favs.Image = Properties.Resources.favsup;
        }
        #endregion

        /// <summary>
        /// Raises the <see cref="E:System.Windows.Forms.Form.Activated"/> event.
        /// It allows to visualize the <see cref="Login"/> form before the <see cref="Welcome"/> form.
        /// </summary>
        /// <param name="e">An <see cref="T:System.EventArgs"/> that contains the event data.</param>
        protected override void OnActivated(EventArgs e)
        {
            if (Welcome.rrp.IsLogged())
            {
                base.OnActivated(e);
            }
        }

        /// <summary>
        /// Raises the <see cref="E:System.Windows.Forms.Control.GotFocus"/> event.
        /// It correcty initializes the welcome message.
        /// </summary>
        /// <param name="e">An <see cref="T:System.EventArgs"/> that contains the event data.</param>
        protected override void OnGotFocus(EventArgs e)
        {
            if (Welcome.rrp.IsLogged())
            {
                if (!(lbl_welcome.Text.Contains(Welcome.rrp.GetCurrentUserName())))
                    this.lbl_welcome.Text += Welcome.rrp.GetCurrentUserName() + "!";
                base.OnGotFocus(e);
            }
        }

        #region View
        /// <summary>
        /// Paints the background of the control.
        /// </summary>
        /// <param name="e"></param>
        protected override void OnPaintBackground(PaintEventArgs e) { }

        /// <summary>
        /// Raises the <see cref="E:System.Windows.Forms.Control.Paint"/> event.
        /// If the user isn't logged shows the <see cref="Login"/> form.
        /// </summary>
        /// <param name="e">A <see cref="T:System.Windows.Forms.PaintEventArgs"/> that contains the event data.</param>
        protected override void OnPaint(PaintEventArgs e)
        {
            if (Welcome.rrp.IsLogged())
            {
                using (Graphics g = e.Graphics)
                    g.DrawImage(m_DoubleBuffer, 0, 0);

                base.OnPaint(e);
            }
            else
            {
                m_LoginForm.ShowDialog();
                if (Welcome.rrp.IsLogged())
                {
                    if (Welcome.rrp.GetCurrentAvatar() != null)
                        this.btn_avatar.Image = Welcome.rrp.GetCurrentAvatar();
                }
            }
        }

        /// <summary>
        /// Fills the double buffer, updating it.
        /// Because of the static aspect, this method can safely be invoked 
        /// only when a real change is applyed to the aspect.
        /// </summary>
        private void FillDoubleBuffer()
        {
            int borderWidth = 4; //width of the external border
            int lOffset = 3; //offset of buttons from the border
            int rOffset = 9; //offset of buttons from the border
            int tOffset = 5; //offset of buttons from the border
            int bOffset = 5; //offset of buttons from the border
            int top = btn_search.Top - borderWidth - tOffset;
            int left = btn_search.Left - borderWidth - lOffset;
            int right = btn_config.Right + borderWidth + rOffset;
            int bottom = lbl_offered.Bottom + borderWidth + bOffset;

            //Image buffer = new Bitmap(ClientSize.Width, ClientSize.Height);
            using (Graphics g = Graphics.FromImage(m_DoubleBuffer))
            {
                g.Clear(BackColor);

                using (Pen p = new Pen(Color.FromArgb(133, 186, 2), borderWidth))
                {

                    //underCircles
                    g.DrawEllipse(p, right - 66, bottom - 30, 50, 50);
                    g.DrawEllipse(p, right - 107, bottom - 22, 44, 44);
                    g.DrawEllipse(p, right - 132, bottom - 27, 31, 31);

                    g.DrawRectangle(p, left, top, right - left, bottom - top);

                    //rightCircles
                    g.DrawEllipse(p, right - 21/*19*/, bottom - 11, 26, 26);
                    g.DrawEllipse(p, right + 2, bottom - 14, 12, 12);
                    g.DrawEllipse(p, right - 5, bottom - 42, 24, 24);


                }
                using (Brush b = new SolidBrush(Color.FromArgb(222, 241, 126)))
                {
                    //underCircles
                    //g.FillEllipse(b, right - 132 + 1, bottom - 27 + 1, 31 - 1, 31 - 1);
                    using (Brush b1 = new SolidBrush(Color.FromArgb(79, 105, 1)))
                        g.FillEllipse(b1, right - 132, bottom - 27, 31, 31);
                    using (Brush b1 = new SolidBrush(Color.FromArgb(133, 186, 2)))
                        g.FillEllipse(b1, right - 130, bottom - 25, 27, 27);

                    //g.FillEllipse(b, right - 107 + 1, bottom - 22 + 1, 44 - 1, 44 - 1);
                    using (Brush b1 = new SolidBrush(Color.FromArgb(133, 185, 2)))
                        g.FillEllipse(b1, right - 107, bottom - 22, 44, 44);
                    using (Brush b1 = new SolidBrush(Color.FromArgb(200, 251, 0)))
                        g.FillEllipse(b1, right - 105, bottom - 20, 40, 40);
                    using (Brush b1 = new SolidBrush(Color.FromArgb(141, 191, 19)))
                        g.FillEllipse(b1, right - 101, bottom - 16, 32, 32);
                    using (Brush b1 = new SolidBrush(Color.FromArgb(253, 253, 249)))
                        g.FillEllipse(b1, right - 99, bottom - 14, 28, 28);
                    using (Brush b1 = new SolidBrush(Color.FromArgb(141, 191, 19)))
                        g.FillEllipse(b1, right - 94, bottom - 9, 18, 18);
                    using (Brush b1 = new SolidBrush(Color.FromArgb(56, 59, 48)))
                        g.FillEllipse(b1, right - 92, bottom - 7, 14, 14);
                    using (Brush b1 = new SolidBrush(Color.FromArgb(141, 191, 19)))
                        g.FillEllipse(b1, right - 89, bottom - 4, 8, 8);

                    //g.FillEllipse(b, right - 66 + 1, bottom - 30 + 1, 50 - 1, 50 - 1);
                    using (Brush b1 = new SolidBrush(Color.FromArgb(80, 106, 0)))
                        g.FillEllipse(b1, right - 66, bottom - 30, 50, 50); //4
                    using (Brush b1 = new SolidBrush(Color.FromArgb(133, 186, 2)))
                        g.FillEllipse(b1, right - 62, bottom - 26, 42, 42); //3
                    using (Brush b1 = new SolidBrush(Color.FromArgb(5, 105, 0)))
                        g.FillEllipse(b1, right - 59, bottom - 23, 36, 36); //4
                    using (Brush b1 = new SolidBrush(Color.FromArgb(254, 254, 254)))
                        g.FillEllipse(b1, right - 55, bottom - 19, 28, 28); //3
                    using (Brush b1 = new SolidBrush(Color.FromArgb(133, 186, 2)))
                        g.FillEllipse(b1, right - 52, bottom - 16, 22, 22); //5
                    using (Brush b1 = new SolidBrush(Color.FromArgb(248, 254, 170)))
                        g.FillEllipse(b1, right - 47, bottom - 11, 12, 12);

                    g.FillRectangle(b, left + 1, top + 1, right - left - 1, bottom - top - 1);

                    //rightCircles
                    //g.FillEllipse(b, right - 21 + 1, bottom - 11, 26 - 1, 26 - 1);
                    using (Brush b1 = new SolidBrush(Color.FromArgb(3, 99, 3)))
                        g.FillEllipse(b1, right - 21, bottom - 11, 26, 26); //4
                    using (Brush b1 = new SolidBrush(Color.FromArgb(194, 246, 0)))
                        g.FillEllipse(b1, right - 17, bottom - 7, 18, 18); //4
                    using (Brush b1 = new SolidBrush(Color.FromArgb(250, 253, 249)))
                        g.FillEllipse(b1, right - 13, bottom - 3, 10, 10); //3
                    using (Brush b1 = new SolidBrush(Color.FromArgb(102, 103, 100)))
                        g.FillEllipse(b1, right - 10, bottom, 4, 4);
                    using (Brush b1 = new SolidBrush(Color.FromArgb(105, 110, 93)))
                        g.FillEllipse(b1, right - 9, bottom + 1, 2, 2);

                    //g.FillEllipse(b, right + 2 + 1, bottom - 14 + 1, 12 - 1, 12 - 1);
                    using (Brush b1 = new SolidBrush(Color.FromArgb(3, 99, 3)))
                        g.FillEllipse(b1, right + 2, bottom - 14, 12, 12);
                    using (Brush b1 = new SolidBrush(Color.FromArgb(194, 246, 0)))
                        g.FillEllipse(b1, right + 4, bottom - 12, 8, 8);
                    using (Brush b1 = new SolidBrush(Color.FromArgb(250, 253, 249)))
                        g.FillEllipse(b1, right + 6, bottom - 10, 4, 4);
                    using (Brush b1 = new SolidBrush(Color.FromArgb(102, 103, 100)))
                        g.FillEllipse(b1, right + 7, bottom - 9, 2, 2);

                    //g.FillEllipse(b, right - 5 + 1, bottom - 42 + 1, 24 - 1, 24 - 1);
                    using (Brush b1 = new SolidBrush(Color.FromArgb(3, 99, 3)))
                        g.FillEllipse(b1, right - 5, bottom - 42, 24, 24); //4
                    using (Brush b1 = new SolidBrush(Color.FromArgb(194, 246, 0)))
                        g.FillEllipse(b1, right - 1, bottom - 38, 16, 16); //4
                    using (Brush b1 = new SolidBrush(Color.FromArgb(250, 253, 249)))
                        g.FillEllipse(b1, right + 3, bottom - 34, 8, 8); //3
                    using (Brush b1 = new SolidBrush(Color.FromArgb(102, 103, 100)))
                        g.FillEllipse(b1, right + 5, bottom - 32, 4, 4);

                    using (Brush b1 = new SolidBrush(Color.FromArgb(3, 99, 3)))
                        g.FillEllipse(b1, right - 7, bottom - 18, 9, 9); //1
                    using (Brush b1 = new SolidBrush(Color.FromArgb(194, 246, 0)))
                        g.FillEllipse(b1, right - 6, bottom - 17, 7, 7); //1
                    using (Brush b1 = new SolidBrush(Color.FromArgb(250, 253, 249)))
                        g.FillEllipse(b1, right - 5, bottom - 16, 5, 5); //1
                    using (Brush b1 = new SolidBrush(Color.FromArgb(102, 103, 100)))
                        g.FillEllipse(b1, right - 4, bottom - 15, 3, 3);

                    using (Brush b1 = new SolidBrush(Color.FromArgb(3, 99, 3)))
                        g.FillEllipse(b1, right, bottom - 24, 9, 9); //1
                    using (Brush b1 = new SolidBrush(Color.FromArgb(194, 246, 0)))
                        g.FillEllipse(b1, right + 1, bottom - 23, 7, 7); //1
                    using (Brush b1 = new SolidBrush(Color.FromArgb(250, 253, 249)))
                        g.FillEllipse(b1, right + 2, bottom - 22, 5, 5); //1
                    using (Brush b1 = new SolidBrush(Color.FromArgb(102, 103, 100)))
                        g.FillEllipse(b1, right + 3, bottom - 21, 3, 3);
                }
            }
        }
        #endregion

        /* METTI QUESTA AL POSTO DELL?ORIGINALE PER PROVARE SHOWDEATAIL!!!!!!
        protected override void OnPaint(PaintEventArgs e){//finta

            WS_SoapTrip.FullTripInfo andrea=new TripLOAMobile.WS_SoapTrip.FullTripInfo();
            andrea.AcceptSmokers=false;
            andrea.Arrival="arrivo...";
            andrea.Departure="partenza...";
            andrea.DepartureTime=DateTime.Now;
            andrea.FreeSeatNumber=4;
            andrea.EstimatedCost=100;
            andrea.ID=11;
            andrea.Notes="ma che belle note.....";
            TripLOAMobile.WS_SoapTrip.UserInfo app = new TripLOAMobile.WS_SoapTrip.UserInfo();
            app.Nickname = "Andrea Vandin";
            app.UserID = 30;

            andrea.Owner = app;
            andrea.ReservatedUsers=new TripLOAMobile.WS_SoapTrip.UserInfo[4];

            app = new TripLOAMobile.WS_SoapTrip.UserInfo();
            app.UserID=0;
            app.Nickname="Andrea Russino";
            andrea.ReservatedUsers[0]=app;

            app= new TripLOAMobile.WS_SoapTrip.UserInfo();
            app.UserID=1;
            app.Nickname="Luca Mastrini";
            andrea.ReservatedUsers[1]=app;

            app= new TripLOAMobile.WS_SoapTrip.UserInfo();
            app.UserID=2;
            app.Nickname="Sara Beraradelli";
            andrea.ReservatedUsers[2]=app;

            app= new TripLOAMobile.WS_SoapTrip.UserInfo();
            app.UserID=3;
            app.Nickname="Alessandro Pulidori";
            andrea.ReservatedUsers[3]=app;

            andrea.ReservationExpirationDate=DateTime.MaxValue;
            
            ShowDetails detForm = new ShowDetails(andrea,true);
            detForm.ShowDialog();       
        }
*/

        /// <summary>
        /// Handles the Click event of the btn_avatar control, by opening a <see cref="OpenFileDialog"/> for the avatar image.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void btn_avatar_Click(object sender, EventArgs e)
        {
            try
            {
                OpenFileDialog openImage = new OpenFileDialog();
                openImage.Filter = "Image Files(*.jpg; *.jpeg; *.gif; *.bmp; *.png)|*.jpg; *.jpeg; *.gif; *.bmp; *.png;";
                if (openImage.ShowDialog() == DialogResult.OK)
                {
                    Welcome.rrp.SetAndLoadCurrentAvatar(openImage.FileName);
                    this.btn_avatar.Image = Welcome.rrp.GetCurrentAvatar();
                }
            }
            catch (Exception)
            {
                MessageBox.Show("Failed loading image");
            }

        }

        /// <summary>
        /// Handles the Click event of the btn_search control, by showing a <see cref="SearchTravel"/> form.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void btn_search_Click(object sender, EventArgs e)
        {
            SearchTravel st = new SearchTravel(Welcome.MaxnumberOfResult);
            formBuffer.Add(st,"SearchTravel");
            this.btn_search.Image = Properties.Resources.searchup;
            st.ShowDialog();
            st.Dispose();
            /*System.Diagnostics.Debug.WriteLine("stato ricerca:" + st.SearchStatus);
            System.Diagnostics.Debug.WriteLine("La lista di risultati:");
            foreach (WS_SoapTrip.TripInfo t in st.ListOfResults)
            {
                System.Diagnostics.Debug.WriteLine(t.ToString());
            }
            maxNumberOfResult = st.ListOfResults.Length;//in futuro andarà levato (quando effettivamente mi ritorneranno il numero di viaggi che gli ho chiesto...)
            ShowSearchResult ssr = new ShowSearchResult(st.ListOfResults,st.SearchStatus,maxNumberOfResult);
            ssr.ShowDialog();*/
            
        }

        /// <summary>
        /// Handles the Click event of the btn_booked control, by showing a <see cref="ShowBooked"/> form.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void btn_booked_Click(object sender, EventArgs e)
        {
            this.btn_booked.Image = Properties.Resources.bookedup;
            //ShowBookedTravel sb = new ShowBookedTravel();
            ShowBooked sb = new ShowBooked();
            formBuffer.Add(sb,"ShowBooked");
            //TripLOAMobile.WS_SoapTrip.TripInfo[] listOfBooked=Welcome.rrp.GetAllMyBookings(0, 4, out aaa);
            //ShowBookedTravel sb = new ShowBookedTravel(listOfBooked, aaa, 4);
            sb.ShowDialog();
            sb.Dispose();
            //prima vedi di chiedere info al sistema centrale e uniscile con quelle in cache...
            //poi apri una form e mostra "listOfBookedTrip" (probabilmente showsearchresult può andare bene/o qualcosa di simile )...
        }

        /// <summary>
        /// Handles the Click event of the btn_insert control, by showing a <see cref="InsertTravel"/> form.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void btn_insert_Click(object sender, EventArgs e)
        {
            InsertTravel it = new InsertTravel();
            formBuffer.Add(it,"InsertTravel");
            this.btn_insert.Image = Properties.Resources.insertup;
            it.ShowDialog();
            it.Dispose();
        }

        /// <summary>
        /// Handles the Click event of the btn_offered control, by showing a <see cref="ShowOffered"/> form.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void btn_offered_Click(object sender, EventArgs e)
        {
            this.btn_offered.Image = Properties.Resources.offeredup;
            //ShowOffered so = new ShowOffered();
            ShowOffered so = new ShowOffered();
            formBuffer.Add(so,"ShowOffered");
            so.ShowDialog();
            so.Dispose();
         //levati perchè aprire una nuova dialog
         //   Invalidate();
         //   Update();
        }

        /// <summary>
        /// Handles the Click event of the btn_config control, by showing a <see cref="Config"/> form.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void btn_config_Click(object sender, EventArgs e)
        {
            this.btn_config.Image = Properties.Resources.configup;
            Config conf = new Config();
            formBuffer.Add(conf,"Config");
            conf.ShowDialog();
            conf.Dispose();
            //levati perchè aprire una nuova dialog
            //   Invalidate();
            //   Update();
        }

        /// <summary>
        /// Handles the Click event of the btn_favs control, by showing a <see cref="ShowFavorites"/> form.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void btn_favs_Click(object sender, EventArgs e)
        {
            this.btn_favs.Image = Properties.Resources.favsup;
            //ShowFavorites sf = new ShowFavorites();
            ShowFavorites sf = new ShowFavorites();
            formBuffer.Add(sf,"ShowFavorites");
            sf.ShowDialog();
            sf.Dispose();
            //levati perchè aprire una nuova dialog
            //   Invalidate();
            //   Update();
        }

        /// <summary>
        /// Handles the Click event of the menuItem1 control, by storing all related data and logging out the user.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void menuItem1_Click(object sender, EventArgs e)
        {
            this.btn_avatar.Image = this.standardAvatar;
            //this.lbl_welcome = (ResourceManager.Instance.Culture.Name == "it-IT") ? 
            UpdateControls(lbl_welcome);
            Welcome.rrp.Logout();
            Invalidate();
            Update();
        }

        /// <summary>
        /// Handles the Click event of the lbl_welcome control, by requesting the user profile.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void lbl_welcome_Click(object sender, EventArgs e)
        {
            rrp.GetCurrentProfile(this, rrp_ProfileResponse);
            this.startAnimation();
        }

        /// <summary>
        /// Handles the RRP response that follows the profile request, by showing a <see cref="ShowProfileInfo"/> form.
        /// </summary>
        /// <param name="e">The <see cref="TripLOAMobile.RemoteResourceProvider.ProfileResponseEventArgs"/> instance containing the event data.</param>
        void rrp_ProfileResponse(RemoteResourceProvider.ProfileResponseEventArgs e)
        {
            this.stopAnimation();
            if (e.Status == RemoteResourceProvider.okStatus)
            {
                ShowProfileInfo p = new ShowProfileInfo(e.Profile, rrp.GetCurrentFeedbacks(), true);
                formBuffer.Add(p,"ShowProfileInfo");
                p.ShowDialog();
                p.Dispose();
            }
            else MessageBox.Show(e.Status);
        }

        /// <summary>
        /// Handles the Click event of the pictureMessage control, by showing a <see cref="ShowMessageBox"/> form.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void pictureMessage_Click(object sender, EventArgs e)
        {
            ShowMessageBox inbox = new ShowMessageBox();
            formBuffer.Add(inbox,"ShowMessageBox");
            inbox.ShowDialog();
            inbox.Dispose();
        }

        /// <summary>
        /// Handles the Click event of the pictureBell control, by showing a <see cref="ViewNotifications"/> form.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void pictureBell_Click(object sender, EventArgs e)
        {
            ViewNotifications notification = new ViewNotifications();
            formBuffer.Add(notification,"ViewNotifications");
            notification.ShowDialog();
            notification.Dispose();
        }
    }
}